/*
    该程序仅用于设置垂直转移是否按照正常\反转的方式工作
*/

#include "MephistoCAM.h"

void print_opts();

int main( int argc, char *argv[] ){

    if( argc != 2 ){
        printf("> usage: %s opt (0/1/2/3) \n", argv[0]);
        print_opts();
        exit(0);
    }

    int opt = atoi(argv[1]);

    int fd = open("/dev/mem", O_RDWR | O_SYNC);
    uint *ptr1 = mmap(NULL, 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ADDR_GPIO_OUT);
    uint *gpio_reg      = ptr1;     // 0x41200000

    if( opt == 0 ){
    // {A1,A0} = {0,0}
        printf("> 0: default configuration, A section transfer to EF, D section transfer to GH\n");
        clrbit(*gpio_reg, BIT_VTRANS_A1);
        clrbit(*gpio_reg, BIT_VTRANS_A0);
    } else if( opt == 1 ){
    // {A1,A0} = {0,1}
        printf("> 1: A and D sections both transfer to EF\n");
        clrbit(*gpio_reg, BIT_VTRANS_A1);
        setbit(*gpio_reg, BIT_VTRANS_A0);
    } else if( opt == 2 ){
    // {A1,A0} = {1,0}
        printf("> 2: A and D sections both transfer to GH\n");
        setbit(*gpio_reg, BIT_VTRANS_A1);
        clrbit(*gpio_reg, BIT_VTRANS_A0);
    } else if( opt == 3 ){
    // {A1,A0} = {1,1}
        // setbit(*gpio_reg, BIT_VTRANS_A1);
        // setbit(*gpio_reg, BIT_VTRANS_A0);
        printf("> 3: A section transfer to GH, D section transfer to EF\n");
        printf("> However, this opt is not to be used at this debug stage ...\n");
        return 0;
    } else {
        printf("> opt must be one of 0/1/2/3!\n");
        exit(0);
    }

    munmap(ptr1,10);
    close(fd);

    return 0;
}


void print_opts(){
    printf("> opt MUST be one of (0/1/2/3):\n");
    printf("> 0: default configuration, A section transfer to EF, D section transfer to GH\n");
    printf("> 1: A and D sections both transfer to EF\n");
    printf("> 2: A and D sections both transfer to GH\n");
    printf("> 3: A section transfer to GH, D section transfer to EF\n");
}
